<!DOCTYPE html>
<html>
<head>
    <base href="../"/>
    <meta charset="UTF-8">
    <title>Basic DataGrid - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="component/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="component/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="css/app.css">
    <script type="text/javascript" src="component/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="component/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="component/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="js/config.js"></script>
</head>
<body class="easyui-layout" fit="true">
<table id="setting_rule_code_datagrid" class="easyui-datagrid"
       data-options="toolbar:'#setting_rule_code_datagrid_tb', method:'get', border:true,singleSelect:true,fit:true,fitColumns:true">
    <thead>
    <tr>
        <th data-options="field:'groupName'" width="100">分组</th>
        <th data-options="field:'name'" width="100">名称</th>
        <th data-options="field:'enable'" width="50">启用</th>
        <th data-options="field:'create_time'" width="100">创建时间</th>
    </tr>
    </thead>
</table>
<div id="setting_rule_code_datagrid_tb">
    <div  style="float: left">
        <a id="add_rule_button" href="javascript:" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新建规则代码</a>
        <a id="enable_rule_button" href="javascript:" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">启用规则</a>
    </div>
    <div style="float: right;">
        <input class="easyui-searchbox" style="width: 200px;"
               data-options="searcher:setting_rule_code_datagrid_tb_search,prompt:'查找'">
    </div>
    <div style="clear: both;"></div>
</div>
<script>
    $(document).ready(function () {
        $('#setting_rule_code_datagrid').datagrid({
            idField: 'id',
            url: baseUrl + '/caculatecode/list.do',
            onDblClickRow : function(index, row){
                $('#rule_code_env_dialog').dialog({
                    title: 'My Dialog',
                    width: '40%',
                    height: '40%',
                    closed: false,
                    cache: false,
                    href: 'app/rule_code_env.html',
                    modal: true,
                    buttons:[{
                        iconCls:'icon-ok',
                        text:'确定',
                        handler:function(){
                            $('#rule_code_env_datagrid').edatagrid('saveRow');
                            $('#rule_code_env_dialog').dialog('close');
                        }
                    },{
                        iconCls:'icon-cancel',
                        text:'退出',
                        handler:function(){
                            $('#rule_code_env_dialog').dialog('close');
                        }
                    }]
                });
            }
        });
        $('#add_rule_button').linkbutton({
            onClick: function () {
                $('#add_rule_code_dialog').dialog({
                    title: 'My Dialog',
                    width: '60%',
                    height: '60%',
                    closed: false,
                    cache: false,
                    href: 'app/add_rule_code.html',
                    modal: true,
                    buttons:[{
                        iconCls:'icon-ok',
                        text:'确定',
                        handler:function(){
                            var valid = $('#add_rule_code_form').form('validate');
                            if(valid){
                                $('#add_rule_code_form').submit();
                                $('#add_rule_code_dialog').dialog('close');
                            }else{
                                $.messager.show({title: '警告', msg:  '无法保存，请修正红色提示区域！'});
                            }
                        }
                    },{
                        iconCls:'icon-cancel',
                        text:'取消',
                        handler:function(){
                            $('#add_rule_code_dialog').dialog('close');
                        }
                    }]
                });
            }
        });
        $('#enable_rule_button').linkbutton({
            onClick: function () {
                $.messager.confirm({
                    title: '请确认',
                    msg: '确认启用改规则?',
                    fn: function(r){
                        if (r){
                            var row = $('#setting_rule_code_datagrid').datagrid('getSelected');
                            $.post(baseUrl + "/caculatecode/enable.do", {id: row.id}, function (data, textStatus, jqXHR) {
                                $('#setting_rule_code_datagrid').datagrid('reload');
                                $.messager.show({
                                    title:'提示',
                                    msg:'操作成功',
                                    timeout:1000,
                                    showType:'slide'
                                });
                            }, "json");
                        }
                    }
                });
            }
        });
    });

    function setting_rule_code_datagrid_tb_search(value) {
        $('#setting_rule_code_datagrid').datagrid('load', {name: value});
    }
</script>
</body>
</html>